package com.ajk.server.model.request;


import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.ArrayUtils;
import org.springframework.web.multipart.MultipartFile;

import com.ajk.server.model.Treatment;
import com.ajk.server.model.TreatmentPic;
import com.ajk.server.utils.FileStoreUtil;

public class TreatmentReq extends Treatment {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Integer[] deletePicIds;

	private MultipartFile[] files;
	
	private List<TreatmentPic> treatmentPics;
	
	private Long actionTimeTs;

	public MultipartFile[] getFiles() {
		return files;
	}

	public void setFiles(MultipartFile[] files) {
		this.files = files;
	}
	
	public List<TreatmentPic> getTreatmentPics() {
		return treatmentPics;
	}

	public void setTreatmentPics(List<TreatmentPic> treatmentPics) {
		this.treatmentPics = treatmentPics;
	}
	
	

	public Integer[] getDeletePicIds() {
		return deletePicIds;
	}

	public void setDeletePicIds(Integer[] deletePicIds) {
		this.deletePicIds = deletePicIds;
	}
	
	

	public Long getActionTimeTs() {
		return actionTimeTs;
	}

	public void setActionTimeTs(Long actionTimeTs) {
		this.actionTimeTs = actionTimeTs;
	}

	@Override
	public void dealWith() {
		super.dealWith();
		if (ArrayUtils.isNotEmpty(files)) {
			treatmentPics = new ArrayList<TreatmentPic>();
			for (MultipartFile multipartFile : files) {
				if(multipartFile!=null && multipartFile.getSize()>0){
					String fileDbName = FileStoreUtil.storeFile(multipartFile, "treatment/pic/");
					
					TreatmentPic pic = new TreatmentPic();
					treatmentPics.add(pic);
					pic.setInUsed(1);
					pic.setPath(fileDbName);
				}
			}
		}else{
			treatmentPics = null;
		}
		if(actionTimeTs!=null && actionTimeTs>0){
			setActionTime(new Date(actionTimeTs));
		}
	}
}